package com.krtech.wecard.module.sys.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.krtech.wecard.framework.aop.Metrics;
import com.krtech.wecard.framework.model.CommRes;
import com.krtech.wecard.module.sys.entity.SysUser;
import com.krtech.wecard.module.sys.entity.SysUserOperateLog;
import com.krtech.wecard.module.sys.service.SysUserOperateLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/sys/operate")
@Api(tags = "用户管理")
@Slf4j
public class UserOperateLogController {

    @Autowired
    private SysUserOperateLogService userOperateLogService;

    @GetMapping("/page")
    @ApiOperation(value = "page")
    public CommRes<Page<SysUserOperateLog>> getUserListByDeptPage(Page<SysUserOperateLog> page,  String keyword,String userId) {
        //查询这个deptId以及下属deptId
        QueryWrapper<SysUserOperateLog> wrapper = new QueryWrapper<>();

        wrapper.eq(SysUserOperateLog.COL_USER_ID,userId);

        if (StrUtil.isNotEmpty(keyword)){
            wrapper.like(SysUserOperateLog.COL_NICK_NAME,keyword)
                    .or()
                    .like(SysUserOperateLog.COL_USER_CODE,keyword)
                    .or()
                    .like(SysUserOperateLog.COL_FROM_INFO,keyword)
                    .or()
                    .like(SysUserOperateLog.COL_TO_INFO,keyword);
        }




        Page<SysUserOperateLog> userPage = userOperateLogService.page(page, wrapper);

        return CommRes.ok(userPage);
    }
}
